package com.hlkj.tool.results;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSON;
import org.apache.struts2.ServletActionContext;

public class JsonResult
  implements Result
{
  private static final long serialVersionUID = 1L;

  public void execute(ActionInvocation invocation)
    throws Exception
  {
    HttpServletResponse response = ServletActionContext.getResponse();
    response.setContentType("application/json; charset=UTF-8");
    PrintWriter writer = response.getWriter();

    JSON json = ResultParameters.getJson();
    if (json != null)
    {
      System.out.println("返回Json:\r\n" + json);

      json.write(writer);
      return;
    }
  }
}